using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Abp.Authorization.Users;
using Abp.Extensions;

namespace Vecen.BangChuang.Authorization.Users {
    public class User: AbpUser<User> {
        public const string DefaultPassword = "123qwe";

        public const string UserAvatarAttachmentType = "UserAvatar";

        public static string CreateRandomPassword() {
            return Guid.NewGuid().ToString("N").Truncate(16);
        }

        /// <summary>
        /// 用户城市
        /// </summary>
        public long? AreaCode { get; set; }

        /// <summary>
        /// 提现密码
        /// </summary>
        public string WithdrawPassword { get; set; }

        /// <summary>
        /// 用户微信号
        /// </summary>
        public string WeChat { get; set; }

        /// <summary>
        /// 推荐人
        /// </summary>
        public long? Recommend { get; set; }


        /// <summary>
        /// 
        /// </summary>
        [ForeignKey(nameof(Recommend))]
        public User RecommendUser { get; set; }

        public override string Name { get; set; } = "";
        
        [Required(AllowEmptyStrings = true)]
        public override string EmailAddress { get; set; } = "";
        public override string Surname { get; set; } = "";

        /// <summary>
        /// 内部用户
        /// </summary>
        public bool IsInner { get; set; }

        /// <summary>
        /// 大学名称
        /// </summary>
        public string UniversityName { get; set; }

        /// <summary>
        /// 学院名称
        /// </summary>
        public string CollegeName { get; set; }

        public static User CreateTenantAdminUser(int tenantId, string emailAddress) {
            var user = new User {
                TenantId = tenantId, UserName = AdminUserName, Name = AdminUserName, Surname = AdminUserName,
                EmailAddress = emailAddress
            };

            user.SetNormalizedNames();

            return user;
        }
    }
}